package com.quanshu.exchange.ui.gui.profile;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.quanshu.exchange.R;
import com.quanshu.exchange.support.utils.RxViewHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.subjects.BehaviorSubject;

/**
 * 相片选择
 */

public class DialogPhotoSelect extends Dialog {

    @BindView(R.id.take_photo)
    TextView takePhoto;
    @BindView(R.id.select_photo)
    TextView selectPhoto;

    public BehaviorSubject getTakePhotoSubject() {
        return takePhotoSubject;
    }

    private BehaviorSubject takePhotoSubject = BehaviorSubject.create();

    public BehaviorSubject getAlbumSubject() {
        return albumSubject;
    }

    private BehaviorSubject albumSubject = BehaviorSubject.create();

    public DialogPhotoSelect(@NonNull Context context) {
        super(context, R.style.BaseDialog);
        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.BottomAnim);
        //默认的Dialog只有5/6左右的宽度，改为全屏宽度
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_photoselect);
        ButterKnife.bind(this);

        initListener();
    }

    private void initListener() {

        RxViewHelper.getInstance().clicks(takePhoto, o -> takePhotoSubject.onNext(o));

        RxViewHelper.getInstance().clicks(selectPhoto, o -> albumSubject.onNext(o));
    }
}